/**********************************************************
 *
 * 键盘方向键、删除键、复制、粘贴键等事件处理函数
 *
 * *********************************************************/
import { useEditorStore } from 'stores/editorStore';
import { CPosition, EnumEditorEvent } from 'stores/editorModels';


export function useEditorEvent () {
  // store
  const store = useEditorStore();

  // 删除选择组件
  const removeSelectedItems = () => {
    store.execute(EnumEditorEvent.EDITOR_KEY_EVT_DEL);
  };

  // 组件移动
  const moveSelectedItems = (evt: EnumEditorEvent) => {
    store.execute(evt);
  }

  // 复制组件
  const copySelectedItems = () => {
    store.execute(EnumEditorEvent.EDITOR_KEY_EVT_COPY);
  };

  // 粘贴组件
  const pasteSelectedItems = () => {
    store.execute(EnumEditorEvent.EDITOR_KEY_EVT_PASTE);
  };

  //组件对其
  const alignSelectedItems = (evt: EnumEditorEvent) => {
    store.execute(evt);
  }

  //旋转组件
  const rotateSelectedItems = (evt: EnumEditorEvent) => {
    store.execute(evt);
  }

  //取消
  const cancelSelectedItems = () => {
    store.execute(EnumEditorEvent.EDITOR_KEY_EVT_ESC);
  }

  //置顶
  const setSelectedTopLayer = () => {
    store.execute(EnumEditorEvent.EDITOR_BTN_EVT_TOP_LAYER);
  }

  //置底
  const setSelectedBottomLayer = () => {
    store.execute(EnumEditorEvent.EDITOR_BTN_EVT_BOTTOM_LAYER);
  }

  return {
    removeSelectedItems,
    moveSelectedItems,
    copySelectedItems,
    pasteSelectedItems,
    alignSelectedItems,
    rotateSelectedItems,
    cancelSelectedItems,
    setSelectedTopLayer,
    setSelectedBottomLayer
  };
}
